/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2015-6-16
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "highchart", "ajaxServ",  "bizProto","sysmanMain","highchartTheme"],
		function($,  highchart, ajaxServ, bizProto,sysmanMain,highchartTheme) {

			'use strict';

			var _bizProto,
				//锚记datagrid目标元素
				$dg,
				//初始化后的datagrid dom对象
				$grid,
				//编辑弹窗对象及弹窗按钮对象
				$edit_window,window_btn,
				//设置密码弹窗对象及按钮对象
				$password_window,password_btn,
				//业务表单对象
				$form,
				//部门选择框字段
				_defaultConfig ={},
				
				chartConfig ={
					chart: {
			            plotBackgroundColor: null,
			            plotBorderWidth: null,
			            plotShadow: false
			        },
			        credits:{
			        	enabled:false
			        },
			        title: {
			            text: '异常情况'
			        },
			        tooltip: {
			            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
			        },
			        legend:{
			        	labelFormat:'{name}: <b>{y}</b>次 , <b>{percentage:.1f}%</b>'			        	
			        },
			        plotOptions: {
			            pie: {
			                allowPointSelect: true,
			                cursor: 'pointer',
			                dataLabels: {
			                    enabled: false,
			                    distance:-20,
			                    format: '<b>{point.name}</b>:{point.y}件'
			                },
			                style: {
		                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
		                    },
		                    showInLegend: true
			            }
			        }
				},
				
				//url define
				supplyStatisticAllUrl = '/supplyInquiry/query/getStaticInfoAll.action',
				
				
				_colors = ["#ff0033","#99ccff",  "#99cc00"]
				

			var public_method = {
				
				
				init:function(_options){
					
					Highcharts.getOptions().colors = Highcharts.map(_colors, function (color) {
				        return {
				            radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
				            stops: [
				                [0, color],
				                [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
				            ]
				        };
				    });
				    
					private_method.init(_options);
				}
				
			}

			var private_method = {
				init : function(_options) {
					if(window.console)
						console.info('supplyChart modules gets ready and been loaded.');
					
					$.extend(_defaultConfig,_options)
					_bizProto = new bizProto(_options)
					
					private_method.initElement(_bizProto.pageDoc)
					
					$.messager.progress('close');
				},				
				
				//初始化元素
				initElement:function(doc){
					
					
					
					ajaxServ.runAjax({
						url:_bizProto.rootPath + supplyStatisticAllUrl,
						callback:private_method.initChart					
					})
					
					
				},
				
				initChart:function(data){
					private_method.initBaseinfoChart(data.baseinfo)
					private_method.initArchiveChart(data.archive)
					private_method.initQualificationChart(data.qualification)
					private_method.initBadinfomationChart(data.badinfomation)
				},
				
				initBaseinfoChart:function(data){
					var _container =$(_bizProto.pageDoc).find('#supply_baseinfo')
					var _param ={
						title: {
				            text: '基本信息异常'
				        },
						series: [{
							allowPointSelect:true,
				            type: 'pie',
				            name: '所占比例',
				            data: data,
				            events:{click:private_method.chartClick}
				        }]
					}
					
					_param =$.extend({},chartConfig,_param)
					$(_container).highcharts(_param);
				},
				
				initArchiveChart:function(data){
					var _container =$(_bizProto.pageDoc).find('#supply_archive')
					var _param ={
						title: {
				            text: '档案异常'
				        },
						series: [{
							allowPointSelect:true,
				            type: 'pie',
				            name: '所占比例',
				            data: data,
				            events:{click:private_method.chartClick}
				        }]
					}
					
					_param =$.extend({},chartConfig,_param)
					$(_container).highcharts(_param);
				},
			
				//初始化全部业务图表
				initQualificationChart:function(data){
					var _container =$(_bizProto.pageDoc).find('#supply_qualification')
					
					var _param ={
						title: {
				            text: '资质异常'
				        },
						series: [{
							allowPointSelect:true,
				            type: 'pie',
				            name: '所占比例',
				            data: data,
				            events:{click:private_method.chartClick}
				        }]
					}
					
					_param =$.extend({},chartConfig,_param)
					$(_container).highcharts(_param);
					
				},
				
				//初始化全部业务图表
				initBadinfomationChart:function(data){
					var _container =$(_bizProto.pageDoc).find('#supply_badinfomation')
					
					var _param ={
						title: {
				            text: '不良记录'
				        },
						series: [{
							allowPointSelect:true,
				            type: 'pie',
				            name: '所占比例',
				            data: data,
				            events:{click:private_method.chartClick}
				        }]
					}
					
					_param =$.extend({},chartConfig,_param)
					$(_container).highcharts(_param);
					
				},
				

			
				chartClick:function(e){
					//var _series =this.getSelectedSeries();
//					alert('series: ' +e.point.name +' selected. value: ' + e.point.y);
					var _param
					if(e.point.issue){						
						_param= {issue:e.point.issue}							
					}
					
					var initQueryParams = {condition:_param}					
					
					sysmanMain.setModuConf('supplyInquirySelect',{initQueryParams:initQueryParams})
				
					sysmanMain.supplyInquirySelect()
				}
			}
			
			return public_method;

		});